<?php
namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller {
	public function index() {

        $this->display();
    }
    public function login() {

        if (!check_verify($_POST['verify'])) {
            $this->error('验证码输入错误！','index');
        }

    	$admin = M('admin')->where("admin_name = '".$_POST['admin_name']."'")->find();
    	//用户名不存在
    	if(!$admin){
    		$this->error('用户名不存在！','index');
    	}else{
            $_POST['admin_password'] = md5($_POST['admin_password'].C(AES_KEY));
    		$password = M('admin')->where($_POST)->find();
    		if(!$password){
    			$this->error('密码错误！','index');
    		}else{
                $data['admin_id'] = $admin['admin_id'];
                $admininfo = M('admin')->alias('a')->join('left join midi_auth_group_access as ga on a.admin_id = ga.uid')->join('left join midi_auth_group as g on ga.group_id = g.id')->where($data)->find();

                unset($admininfo['admin_password']);
                session('midiadmin',$admininfo);

    			$this->success('登录成功！',U('Index/index'));
    		}
    	}
    }

    public function logout(){
        unset($_SESSION['midiadmin']);
        $this->success('退出成功！',U('Login/index'));
    }

    // 生成验证码
    public function showVerify(){
        show_verify();
    }
}